#include "clientsview.h"
#include "ui_clientsview.h"
#include <QImage>
#include <QDir>
#include "dialogs/cameradialog.h"


ClientsView::ClientsView(int clientId, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ClientsView)
{


    clientdao = new ClientsDAO(this);
    qDebug("editing client :%d",clientId);
    ui->setupUi(this);
    QImage myImage;
    QString filename = QApplication::applicationDirPath();
    filename.append(":user.png");
    qDebug(filename.toLatin1());
    myImage.load(":/icarus/user.png");
    ui->profilePicture->setPixmap(QPixmap::fromImage(myImage));
    connect(ui->profilePicButton,SIGNAL(clicked()),this,SLOT(showCameraDialog()));

    Client *client = clientdao->getClient(clientId);

    ui->nameEdit->setText(*client->getName());
    //ui->lastnameEdit->setText(*client->getLastName());
    //ui->addressEdit->setText(*client->getAddress());
    //ui->nameEdit->setText(client->getName());


}

ClientsView::~ClientsView()
{
    delete ui;
}

void ClientsView::showCameraDialog(){

    CameraDialog *dialog = new CameraDialog();
    dialog->show();

    connect(dialog,SIGNAL(accepted()),this,SLOT(pictureTaken()));

}

void ClientsView::pictureTaken(){
    pictureTaken();
}
